package top.jiangqiang.qianyi.common.crypto;

import lombok.RequiredArgsConstructor;
import org.dromara.hutool.crypto.asymmetric.KeyType;

/**
 * @Date 2024/6/7 下午12:05
 * @Author Jiangqiang
 */
@RequiredArgsConstructor
public class DefaultEncryptService implements EncryptService {
    private final CryptoService cryptoService;

    @Override
    public String dbEncrypt(String rawText) {
        return cryptoService.aesEncrypt(rawText);
    }

    @Override
    public String dbDecrypt(String encodedText) {
        return cryptoService.aesDecrypt(encodedText);
    }

    @Override
    public String passwordEncrypt(String rawText) {
        return cryptoService.encode(rawText);
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return cryptoService.matches(rawPassword, encodedPassword);
    }

    @Override
    public String httpEncrypt(String rawText) {
        return cryptoService.rsaEncrypt(rawText);
    }

    @Override
    public String httpDecrypt(String encodedText) {
        return cryptoService.rsaDecrypt(encodedText);
    }

    @Override
    public String frontEndEncrypt(String data) {
        return cryptoService.rsaEncrypt(data, KeyType.PublicKey);
    }

    @Override
    public String frontEndDecrypt(String data) {
        return cryptoService.rsaDecrypt(data, KeyType.PublicKey);
    }
}
